package 晚间作业0420

import 晚间作业0420.Scala_03_04.RGB.{BLACK, BLUE, CYAN, GREEN, PURPLE, RED, RGB, WHITE, YELLOW}
import 晚间作业0420.Scala_03_Exp_02.Card.Card

// 实战案例一
object Scala_03_Exp_01 {

  trait UnitConversion {
    def factor: Double
    def converse(from: Double): Double
  }

  object inchesToCentimeters extends UnitConversion {
    override def factor: Double = 30.48
    override def converse(inches: Double): Double = inches * factor
  }

  object gallonToLiters extends UnitConversion {
    override def factor: Double = 3.785311784
    override def converse(gallon: Double): Double = gallon * factor
  }

  object milesToKilometers extends UnitConversion {
    override def factor: Double = 1.609344
    override def converse(mile: Double): Double = mile * factor
  }

  def main(args: Array[String]): Unit = {
    println(s"10英尺=${inchesToCentimeters.converse(10)}厘米")
    println(s"10厘米=${gallonToLiters.converse(10)}加仑")
    println(s"10英里=${milesToKilometers.converse(10)}公里")
  }
}

// 实战案例二
object Scala_03_Exp_02 {
  object Card extends Enumeration {
    val spade, heart, diamonds, club = Value
    type Card = Value
  }

  def judgeColor(c: Card): Unit = if (c == Card.heart || c == Card.diamonds) println("Red") else println("Black")

  def main(args: Array[String]): Unit = {
    judgeColor(Card.heart)
    judgeColor(Card.spade)
  }
}

// 课后作业1
object Scala_03_01 {
  abstract class Computer(var cpu: String, var memory: String, var disk: String) { def getDetails }

  class PC(cpu: String, memory: String, disk: String, var brand: String) extends Computer(cpu, memory, disk) {
    override def getDetails: Unit = println(s"${brand}PC, CPU->$cpu, 内存->$memory, 硬盘->$disk")
  }

  class NotePad(cpu: String, memory: String, disk: String, var color: String) extends Computer(cpu, memory, disk) {
    override def getDetails: Unit = println(s"NotePad, CPU->$cpu, 内存->$memory, 硬盘->$disk, 颜色->$color")
  }

  def main(args: Array[String]): Unit = {
    new PC("Intel core i7", "16GB", "500GB", "联想扬天").getDetails
    new NotePad("Intel core i7", "16GB", "500GB", "星空蓝").getDetails
  }
}

// 课后作业2
object Scala_03_02 {
  case class Point(var x: Int, var y: Int)
  object Point { def apply(x: Int, y: Int): Point = new Point(x, y) }
  def main(args: Array[String]): Unit = { println(Point(3, 4)) }
}

// 课后作业3
object Scala_03_03 extends App { println(args.reverse.mkString(" ")) }

// 课后作业4
object Scala_03_04 {
  object RGB extends Enumeration {
    val RED = Value(0x0000ff)
    val GREEN = Value(0x00ff00)
    val BLUE = Value(0xff0000)
    val YELLOW = Value(0xffff00)
    val WHITE  = Value(0xffffff)
    val CYAN  = Value(0x00ffff) // 青色
    val BLACK   = Value(0x000000)
    val PURPLE   = Value(0xb273fb)// 紫色
    type RGB = Value
  }

  case class Cube (var points: Map[(Int, Int, Int), RGB])

  def main(args: Array[String]): Unit = {
    println(Cube(Map(
      ((0, 0, 0), RED),
      ((0, 0, 1), GREEN),
      ((0, 1, 0), BLUE),
      ((1, 0, 0), YELLOW),
      ((0, 1, 1), WHITE),
      ((1, 0, 1), CYAN),
      ((1, 1, 0), BLACK),
      ((1, 1, 1), PURPLE)
    )).toString)
  }
}




